<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<div id="container-content" class="container-content">
    <div class="panel panel-default report-container">
        <div class="panel-heading">
            <div class="col-md-2">用户管理</div>
        </div>
        <div class="panel-body">
            <form action="" cssClass="row products-condition" id="myForm">
                <div class="form-inline col-sm-12">
                    <div class="form-group"><h3>渠道用户基本信息</h3></div>
                </div>
                <div class="form-inline col-sm-12">
                    <div class="form-group">
                        <label>用户名称</label>
                        <input id="channelUserName"  cssClass="form-control"/>
                    </div>

                    <%--<div class="form-group">--%>
                        <%--<label>手机号</label>--%>
                        <%--<input id="telPhone" cssClass="form-control"/>--%>
                    <%--</div>--%>
                    <div class="form-group " >
                        <button id="btn_search" type="button" class="btn btn-default pull-right">查询</button>
                    </div>
                </div>
                <input id="total" type="hidden" value="${dataList.totalCount}"/>

            </form>

            <table class="table table-bordered" style="margin-top: 80px">
                <thead>
                <tr>
                    <th>用户名称</th>
                    <th>昵称</th>
                    <th>权限组</th>
                    <th>渠道名</th>
                    <th>手机号</th>
                    <th>邮箱</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="myTable">
                <c:forEach items="${datalist}" var="data" varStatus="a">
                    <tr>
                        <td class="channel-name">${data.adminName}</td>
                        <td>${data.adminNick}</td>
                        <td>${data.groups[0].groupName}</td>
                        <td>${data.channelName}</td>
                        <td class="channel-phone">${data.telPhone}</td>
                        <td>${data.adminEmail}</td>
                        <td>
                        ${data.status==1?"启用":"禁用"}
                        </td>
                        <td>
                            <button  type="button" data-id="${data.adminName}" class="btn btn-default btn-xs edit">编辑用户
                            </button>

                            <button data-id="${data.id}" type="button"   class="btn btn-xs  btn-warning delete" >删除
                            </button>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </div>
    </div>
</div>

<!-- Modal -->
<%--模态框--%>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">编辑用户</h4>
            </div>
            <%--modal-body代表的jsp是appinfoedit.jsp--%>
            <div class="modal-body">
                <iframe id="addViewFrame" name="addViewFrame" width="100%" height="490px" frameborder="0"></iframe>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal" id="closeModel"><span
                        class="glyphicon glyphicon-remove" ></span> 关闭
                </button>

            </div>
        </div>
    </div>
</div>

<script>


    $(document).ready(function(){
        var success="${success}"
        if(success!=""){
            alert(success)
            window.parent.location.href = "${pageContext.request.contextPath}/users/list";
        }
        find()
        $(".edit").click(function(){
            var username = $(this).data("id");
            var frameSrc = "${pageContext.request.contextPath}/users/editUser?username="+username;
            $("#addViewFrame").attr("src", frameSrc);
            $('#myModal').modal({ show: true, backdrop: 'static' });
        });


        $(".delete").click(function(){
            var t= $(this)
            var userId = $(this).data("id");
            if(confirm("确定要删除该用户?")){
                $.getJSON("${pageContext.request.contextPath}/users/remove?userId="+userId, function (data) {//data返回的数据
                    if (data.response.status=="9999"){

                        alert("删除成功")
                        t.parents("tr").remove()

                    }else {
                        alert("删除失败");
                    }
                })
            }




        })
    })

    function a(){
    $("#closeModel").click();
    }

    function find(){
        $("#btn_search").click(function(){
            var name=  $("#channelUserName").val().trim();
            var a= $(".channel-name");
            for(var i=0;i< a.length; i++){
                if($(a[i]).text().indexOf(name)<0){
                    $(a[i]).parent("tr").hide()
                }else{
                    $(a[i]).parent("tr").show()
                }
            }







        })
    }


</script>


